<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html {
            height: 100vh;
            padding: 0;
            margin: 0;
        }

        .bigBox {

            width: 100vw;
            height: 100vh;
            overflow: hidden;
            position: relative;
        }

        .button {
            display: block;
            margin: 20px auto;
        }

        .shade {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(3, 3, 3, 0.219);
            box-sizing: border-box;
            display: none;
        }

        .box {
            width: 30%;
            height: 200px;
            margin: 10% auto;
            border: 5px solid rgb(235, 216, 109);
            background-color: rgb(187, 247, 242);
            /* padding: 0; */
        }

        p {
            margin: 0;
            display: block;
            width: 100%;
            background-color: rgb(241, 213, 100);
            height: 30px;
        }

        .close {
            float: right;
            color: rgb(235, 216, 109);
            background-color: cornsilk;
            padding: 0 10px;
        }
    </style>
</head>

<body>
    <div class="bigBox">
        <!-- 弹出层  按钮 -->
        <!-- <input type="button" value="弹出层" class="button"> -->
        <button class="button">弹出层</button>

        <!-- 遮光罩 -->
        <div class="shade">
            <!-- 弹出框 -->
            <div class="box">
                <p>
                    <span class="close">X</span>
                </p>
            </div>
        </div>


    </div>
</body>

<script type="text/javascript">
    // 1.获取所有节点   
    // 用getElementsByClassName 获取这个button 只是获取到他的“button”，而不是他这个标签  // 获取的是这个元素
    // 用querySelector 选择 他这个标签
    var btn = document.querySelector('.button')  // 弹出框按钮
    var shade = document.querySelector('.shade')  // 遮光罩
    var box = document.querySelector('.box')  // 弹出框
    var close = document.querySelector('.close')  // 关闭

    // 2.点击弹出出现
    btn.onclick = function () {
        shade.style.display = 'block'
    }

    // 3.点击关闭
    close.onclick = function () {
        shade.style.display = 'none'
    }



</script>

</html>